home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 326 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.6 KB  |  99 lines

  1. Path: hecate.umd.edu!ram
  2. From: ram@mbisgi.umd.edu (Ram Samudrala)
  3. Newsgroups: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
  4. Subject: Perl vs.C (was Re: Unix or NT? Get a Mac!)
  5. Followup-To: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
  6. Date: 4 Jan 1996 13:19:06 GMT
  7. Organization: The Centre for Advanced Research in Biotechnology
  8. Message-ID: <4cgk4a$pje@hecate.umd.edu>
  9. Reply-To: me@ram.org
  10. NNTP-Posting-Host: iris3.carb.nist.gov
  11. X-Newsreader: TIN [version 1.2 PL0]
  12.  
  13. I'm posting this on comp.lang.c, and removing c.i.w.authoring.cgi.
  14.  
  15. Mark Woodruff (netcom.com@netcom.com) wrote:
  16.  
  17. >In languages, look for a match between the problem and the language,
  18. >rather than an arbitrary or artificial grading unrelated to the
  19. >problem.
  20.  
  21. My first statement was fairly specific: it was related to the
  22. complexity of the task.  Specifically, I mentioned ACM-type problems
  23. (and stuff related to my own research).  The claims made were along
  24. the lines that Perl is 10 times faster to code than C, and only about
  25. 2-3 times slower in execution (if I recall right). I dispute this
  26. claim for any application once it goes past a certain level.
  27.  
  28. >What if your problem was to search a telephone directory and identify
  29. >anyone with Serbo-Croatian names based on the top most common
  30. >Serbo-Croatian name *forms*? You could code and run the Perl version
  31. >long before you'd even be finished with your first design in C/C++.
  32. >Ya gotta look at the big picture.
  33.  
  34. It depends.  If your "form" can be specified as a regular expression,
  35. you could do it in C with a few lines of code; I just whipped up an
  36. example of doing regular expressions in C---took me 10 minutes to,
  37. including reading the man page (which I essentially ripped off the
  38. code from---the macros are all borrowed from the page).  This is
  39. highly specific to SGI machines, but there' a standard for regexp()
  40. which is simlpler, I believe.  So if you're searching a directory with
  41. tens of thousands of lines, it's clear this native approach is a good
  42. way. Of course, you could simply use egrep, which would make it
  43. one-line thing.
  44.  
  45. Note that I don't consider this very complex and it is probably true
  46. that Perl (or some tool like egrep) would do a better job and/or be
  47. faster to code.  My comment was mainly stating that there's a limit at
  48. which Perl stops being useful.
  49.  
  50. >And what if your problem was to search a *real* telephone directory?
  51. >You could probably hire college students to do it faster by hand than
  52. >you could code it and run it in any language.
  53.  
  54. Search a real telephone directory for what?  If it's a number (i.e.,
  55. given a #, match a name), and if stuff is sorted, then I believe that
  56. coding a binary search in both C and Perl would take about the same
  57. time (could be wrong, I'll admit---if I code something in Perl, it'll
  58. look a lot like my C programs).  If it's a regular expression, I'd use
  59. egrep.
  60.  
  61. --Ram
  62.  
  63. -- regexp example in C --
  64.  
  65. #include <stdio.h>
  66.  
  67. #define INIT register char *sp = instring;
  68. #define GETC() (*sp++)
  69. #define PEEKC() (*sp)
  70. #define UNGETC(c) (--sp)
  71. #define RETURN(c) return;
  72. #define ERROR(c) regerr(c)
  73. #define ESIZE 20000
  74.  
  75. #include <regexp.h>
  76.  
  77. void main(int argc, char *argv[])
  78. {
  79.   char expbuf[ESIZE], line[200];
  80.  
  81.   compile(argv[1], expbuf, &expbuf[ESIZE], '\0');
  82.   while (gets(line))
  83.     {
  84.       if (step(line, expbuf))
  85.     printf("match found in %s\n", line);
  86.     }
  87. }
  88.  
  89. int regerr(int c)
  90. {
  91.   fprintf(stderr, "regerr(): an error has occured: %d!\n", c);
  92.   exit(0);
  93. }
  94.  
  95.  
  96. me@ram.org  ||  http://www.ram.org  ||  http://www.twisted-helices.com/th
  97.                 Unfortunately people are not rebelling against Microsoft.
  98.                                They don't know any better.  ---Steve Jobs
  99.